define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cxdx/order/index' + location.search,
                    add_url: 'cxdx/order/add',
                    edit_url: 'cxdx/order/edit',
                    del_url: 'cxdx/order/del',
                    multi_url: 'cxdx/order/multi',
                    import_url: 'cxdx/order/import',
                    table: 'cxdx_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'batchId', title: __('Batchid'), operate: 'LIKE'},
                        {field: 'serial', title: __('Serial'), operate: 'LIKE'},
                        {field: 'packageID', title: __('Packageid'), operate: 'LIKE'},
                        {field: 'number', title: __('Number')},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'idCard', title: __('Idcard'), operate: 'LIKE'},
                        {field: 'policyNo', title: __('Policyno'), operate: 'LIKE'},
                        {field: 'agencyCode', title: __('Agencycode'), operate: 'LIKE'},
                        {field: 'carNo', title: __('Carno'), operate: 'LIKE'},
                        {field: 'frameCode', title: __('Framecode'), operate: 'LIKE'},
                        {field: 'purchasePrice', title: __('Purchaseprice'), operate:'BETWEEN'},
                        {field: 'clientId', title: __('Clientid'), operate: 'LIKE'},
                        {field: 'timestamp', title: __('Timestamp')},
                        {field: 'token', title: __('Token')},
                        {field: 'dateFrom', title: __('Datefrom'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'dateTo', title: __('Dateto'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
